<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="f"  uri="http://java.sun.com/jsf/core"%>
<%@ taglib prefix="h"  uri="http://java.sun.com/jsf/html"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>POI search system</title>
</head>
<body>
<f:view>
 	<h:form>
 		<h:panelGrid columns="1" border="1">
			<h:panelGrid columns="2" >
				<h:outputLabel value="Location Name"></h:outputLabel>
				<h:inputText  value="#{poiSearch.searchName}"></h:inputText>
				<h:outputLabel value="Location Type"></h:outputLabel>
				<h:selectOneMenu id="poiType" value="#{poiSearch.searchType}" title="Select POI type">
  					<f:selectItem id="poiMy" itemLabel="My" itemValue="My" />
  					<f:selectItem id="poiStore" itemLabel="Store" itemValue="Store" />
  					<f:selectItem id="poiRecreation" itemLabel="Recreation" itemValue="Recreation" />
  					<f:selectItem id="poiFood" itemLabel="Food" itemValue="Food" />
				</h:selectOneMenu>
				<h:outputLabel value="Distance (km)"></h:outputLabel>
				<h:inputText  value="#{poiSearch.searchDistance}"></h:inputText>
				<h:outputLabel value="Home point"></h:outputLabel>
				<h:selectOneMenu id="homePOI" value="#{poiSearch.homePointID}" title="Select home point">
		 			<c:forEach var="poiItem" items="#{poiSearch.myList}" varStatus="status">
	  					<f:selectItem itemLabel="#{poiItem.locationName}" itemValue="#{poiItem.pointID}" />
					</c:forEach>
				</h:selectOneMenu>
			</h:panelGrid>
		</h:panelGrid>
		<br/>
		<h:commandButton action="#{poiSearch.search}" value="Search"></h:commandButton>
		<h:panelGroup rendered="#{poiSearch.resultPresented==true}">
			<c:if test="${poiSearch.smthFound == true}">
				<h3>Finished!</h3>
				<table border=1>
					<tr align=center bgcolor="lightgrey">
						<td>ID</td>
						<td>POI name</td>
					</tr>
					<c:forEach var="foundItem" items="#{poiSearch.searchResult}"  varStatus="status">
						<tr>
							<td><c:out value="${foundItem.pointID}"/></td>
							<td><c:out value="${foundItem.name}"/></td>
						</tr>
					</c:forEach>
				</table>
			</c:if>
			<c:if test="${poiSearch.smthFound == false}">
				<h3>Nothing is found!</h3>
			</c:if>
			<br>
			<h:commandButton action="#{poiSearch.clearResults}" value="Hide search results"></h:commandButton>		
		</h:panelGroup>
	</h:form>
</f:view>
</body>
</html>